package com.aotutest2023;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

/**
 * Created with IntelliJ IDEA.
 * User:xieChao
 * Date:2023/2/6 14:47
 */
public class fristautotest {
     private ChromeDriver driver = new ChromeDriver();
    //1.
//    public void jianlai() throws InterruptedException {
//        ChromeDriver driver = new ChromeDriver();
//        Thread.sleep(3000);
//        driver.get("https://www.baidu.com");
//        Thread.sleep(3000);
//        driver.findElement(By.cssSelector("#kw")).sendKeys("剑来");
//        Thread.sleep(3000);
//        driver.findElement(By.cssSelector("#su")).click();
//        Thread.sleep(3000);
//        driver.quit();
//    }
    public  void start() throws InterruptedException {
        driver.get("https://www.baidu.com");
        Thread.sleep(3000);
    }

    public void Test() throws InterruptedException {
//        //隐式等待    implicitlyWait()
//        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
//
//        driver.findElement(By.cssSelector("#kw")).sendKeys("陈平安");
//       driver.findElement(By.cssSelector("#su")).click();
//       driver.findElement(By.cssSelector("#\\31  > div > h3 > a")).click();
//        Thread.sleep(3000);
//        driver.findElement(By.cssSelector("#kw")).clear();
//        Thread.sleep(3000);



        driver.findElement(By.cssSelector("#kw")).sendKeys("陈平安");
        driver.findElement(By.cssSelector("#su")).click();
        //driver.findElement(By.cssSelector("#\\31  > div > h3 > a")).click();
        //显示等待
        WebDriverWait foo = new WebDriverWait(driver,Duration.ofSeconds(3));
//  foo.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#\\31  > div > h3 > a")));

        //检查页面文本是否对正确
        foo.until(ExpectedConditions.textToBe(By.cssSelector("#\\31  > div > h3 > a"),"陈平安 - 百度百科"));
    }

    public void end() throws InterruptedException {
        Thread.sleep(3000);
        driver.quit();
    }
}
